jQuery(function ($) {
    var url = window.location.pathname;
    var pageOnOff = true;
    getList(0);
    var onoff = false;
    //分页按钮
    function twbsPagination(totalPage) {
        Page({
			num:Math.ceil(totalPage / 15),					//页码数
			startnum:1,				//指定页码
			elem:$('#pagination_b'),		//指定的元素
			callback:function(page){	//回调函数
                if (page != 1) {
                    onoff = true;
                }
                if (onoff) {
                    $('.works_show').empty();
                    getList(page - 1);
                    $('html,body').animate({scrollTop:$('#main ').offset().top-80}, 500);

                }
			}
		});
    };
    //专题列表
    function getList(page) {
            var keywordUrl = url.split('/')[2];
            var keyParam = {
               url:keywordUrl,
               page:page,
               size:15
            };
        
      
        send_ajax('get', '/api/article/catArticleList', keyParam, function callback(res) {
            if (res.code == 200 && res.data) {
                //分页按钮
                if(pageOnOff){
                    twbsPagination(res.data.total);
                    pageOnOff=false;
                }
                var data = res.data.articleList;
                var html = "";
                for (var i = 0; i < data.length; i++) {
                    var a_msg = data[i]
                    html += '<li>\<p class="li_title">\n<a href="/article-' + a_msg.id + '.html" target="blank">\
                        <span class="title_left">\n ' + a_msg.title + "\n </span></a>\
                        <span class=\"time\">畜牧 " + formatDate(new Date(a_msg.update_time)) +  "  \u66F4\u65B0\ </span>\n </p>\
                         <p class=\"li_content\"><span>" + a_msg.summary + '</span>\<a href="/article-' + a_msg.id + ".html\" target=\"blank\">\ <span class=\"red\">[\u5168\u6587]</span>\n </a>\ \</p>\</li>";
                };
                $('.content_list').html(html);
            }
        });
    }
    function formatDate(now) { 
        var year=now.getFullYear(); 
        var month=now.getMonth()+1; 
        var date=now.getDate(); 
        var hour=now.getHours(); 
        var minute=now.getMinutes(); 
        var second=now.getSeconds(); 
        return year+"-"+month+"-"+date+" "+hour+":"+minute+":"+second; 
    } 
});